<template>
	<el-container>
		<el-header>
			<div class="left-panel">
				<sc-export-button :auth="'contract.detailsExport'" :apiObj="shopObj" :search="search"></sc-export-button>
				<!-- 打印-->
				<!-- <sc-print-button :auth="'contract.print'" :selection="selection"></sc-print-button> -->
			</div>
			<div class="right-panel">
				<div class="right-panel-search">
                    <el-input v-model="search.other_code" placeholder="出库单号" clearable @keyup.enter="upsearch"></el-input>
                    <el-input v-model="search.other_name" placeholder="出库名称" clearable @keyup.enter="upsearch"></el-input>
					<el-input v-model="search.goods_name" placeholder="请输入商品名称/商品规格" clearable @keyup.enter="upsearch"></el-input>
					<el-input v-model="search.remark" placeholder="备注" clearable @keyup.enter="upsearch"></el-input>
					<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
					<el-button type="primary" icon="el-icon-refresh" @click="refresh"></el-button>
				</div>
			</div>
		</el-header>
		<el-main class="nopadding">
			<scTable ref="table" row-key="id" :apiObj="shopObj" @selection-change="selectionChange"
					 stripe remoteSort remoteFilter border tableName="otheroutShopTable" :column="defaultColumn" :params="query" @row-dblclick="table_edit">
				<el-table-column type="selection" width="50" reserve-selection align="center"></el-table-column>
				<el-table-column type="index" label="序号" fixed align="center" width="50"></el-table-column>
				<template #is_deliver="scope">
					<el-tag type="danger" v-if="scope.row.send_status == 0"> 未发货</el-tag>
					<el-tag type="success" v-if="scope.row.send_status == 1">发货</el-tag>
				</template>
				<template #is_ticket="scope">
					<el-tag :type="scope.row.is_ticket == 2 ? 'primary' : 'danger'">
						{{ scope.row.is_ticket_string }}
					</el-tag>
				</template>
				<template #status="scope">
					<el-tag type="warning" v-if="scope.row.status == 0">待审核</el-tag>
					<el-tag type="success" v-if="scope.row.status == 1">通过</el-tag>
					<el-tag type="danger" v-if="scope.row.status == 2">驳回</el-tag>
				</template>
			</scTable>
		</el-main>
	</el-container>
	<save-dialog v-if="dialog.save" ref="saveDialog" @success="handleSuccess" @closed="dialog.save = false"></save-dialog>
	<save-production v-if="dialog.production" ref="productionDialog" @success="handleSuccess" @closed="dialog.production = false"></save-production>
	<plan-save v-if="dialog.plan" ref="planDialog" @success="handleSuccess" @closed="dialog.plan = false"></plan-save>
</template>

<script>
import SaveProduction from '@/views/production/plan/save.vue'
import saveDialog from './save'
import planSave from '@/views/procure/plan/save.vue'
import config from "@/config"
export default {
	name: 'BOM列表',
	components: {
		saveDialog, SaveProduction, planSave
	},
	data() {
		return {
			dialog: {
				save: false,
				production: false,
				plan: false,
			},
			shopObj: this.$API.ware.other.detailList,
			selection: [],
			search: {
                other_code: null,
                other_name: null,
                goods_name: null,
                remark: null,
                other_type: 2
			},
            query: {
                other_type: 2
            },
			config:config,
			defaultColumn: [
				{label: "出库单号",prop: "other_code",},
				{label: "出库名称",prop: "other_name",},
				{label: "出库仓库",prop: "ware_name",},
				{label: "出库日期",prop: "other_date",},
				{label: "品名",prop: "goods_name",},
				{label: "规格",prop: "goods_spec",},
				{label: "品牌",prop: "brand_name",},
				{label: "数量",prop: "number",},
				{label: "单价",prop: "price",},
				{label: "金额",prop: "fee",},
				{label: "备注",prop: "remark",},
			],
            edit:this.$TOOL.data.get("PERMISSIONS").includes('otherin.edit')
		}
	},
	mounted() {

	},
	methods: {
		//查看
		table_show(row) {
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open('show').setData(row)
			})
		},
		//表格选择后回调事件
		selectionChange(selection) {
			this.selection = selection;
		},
		//搜索
		upsearch() {
			this.$refs.table.upData(this.search)
		},
		refresh() {
			for (const key in this.search) {
				this.search[key] = null;
			}
			this.$refs.table.upData(this.search)
		},
		//本地更新数据
		handleSuccess(data, mode) {
			if (mode == 'add') {
				this.$refs.table.refresh()
			} else if (mode == 'edit') {
				this.$refs.table.refresh()
			}
		},
		async table_copy(row) {
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open('copy').setData(row, 1)
			})
		},
        table_edit(row) {
			if(this.edit && row.status != 1){
                this.dialog.save = true
                this.$nextTick(() => {
                    this.$refs.saveDialog.open('edit').setData(row)
                })
            }else{
                this.$alert("没有编辑权限", "提示", {type: 'error'})
            }
		},
	}
}
</script>

<style></style>
